package utils.version5;

import java.sql.Connection;
import java.sql.SQLException;


public class TransactionManager {

    private ConnetionFactory factory;

    public TransactionManager(ConnetionFactory factory) {
        this.factory = factory;
    }

    public ConnetionFactory getFactory() {
        return factory;
    }

    private  Connection getCurrentConnection(){
        return  factory.getCurrentConnection();
    }
    public  void start() {
        Connection connection = getCurrentConnection();
        try {
            connection.setAutoCommit(false);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public  void commit() {
        try {
            getCurrentConnection().commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public  void rollback() {
        try {
            getCurrentConnection().rollback();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }




}
